<include file="Common/common" />

<body>
	
	<div class="layui-tab-item layui-show">
		<div class="layui-main">
			<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
			  	<legend  style="color: rgb(240,222,112)">修改账户密码</legend>
			</fieldset>

			<form class="layui-form" id="password-form" action=""  style="color: rgb(240,222,112)">
				<div class="layui-form-item">
					<label class="layui-form-label">原密码</label>
					<div class="layui-input-block">
						<input style="background-color: rgba(255,255,255,0.2); color: rgb(240,222,112);" type="password"  name="oldpwd" lay-verify="required"  autocomplete="off" class="layui-input">
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">新密码</label>
					<div class="layui-input-block">
						<input style="background-color: rgba(255,255,255,0.2); color: rgb(240,222,112);" type="password"  name="newpwd" lay-verify="required"  autocomplete="off" class="layui-input">
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">确认新密码</label>
					<div class="layui-input-block">
						<input style="background-color: rgba(255,255,255,0.2); color: rgb(240,222,112);" type="password"  name="confirm_newpwd" lay-verify="required"  autocomplete="off" class="layui-input">
					</div>
					
				</div>

				<input type="hidden" name="uid" value="{$userInfo['id']}">

				<div class="layui-form-item">
					<div class="layui-input-block" style="margin-left: 105px;">
						<button style="color: rgb(240,222,112);background: rgb(57,61,73);font-size: 16px"   class="layui-btn" lay-submit="" lay-filter="btn-changepwd">立即修改</button>
						<button style="color: rgb(240,222,112);background: rgb(57,61,73);font-size: 16px"  type="reset" class="layui-btn ">重置信息</button>
					</div>
				</div>

			</form>


			<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
			  	<legend  style="color: rgb(240,222,112)">修改交易密码</legend>
			</fieldset>

			<form class="layui-form" id="safe-password-form" action=""  style="color: rgb(240,222,112)">
				<div class="layui-form-item">
					<label class="layui-form-label">原交易密码</label>
					<div class="layui-input-block">
						<input style="background-color: rgba(255,255,255,0.2); color: rgb(240,222,112);" type="password"  name="oldsafe" lay-verify="required"  autocomplete="off" class="layui-input">
						<div class="layui-form-mid layui-word-aux"><span  style="color: rgb(240,222,112)">忘记密码，请在后台留言找回</span></div>
					</div>

				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">新交易密码</label>
					<div class="layui-input-block">
						<input style="background-color: rgba(255,255,255,0.2); color: rgb(240,222,112);" type="password"  name="newsafe" lay-verify="required"  autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">确认新交易密码</label>
					<div class="layui-input-block">
						<input style="background-color: rgba(255,255,255,0.2); color: rgb(240,222,112);" type="password"  name="confirm_newsafe" lay-verify="required"  autocomplete="off" class="layui-input">
					</div>
				</div>

				<input type="hidden" name="uid" value="{$userInfo['id']}">

				<div class="layui-form-item">
					<div class="layui-input-block" style="margin-left: 105px;">
						<button style="color: rgb(240,222,112);background: rgb(57,61,73);font-size: 16px"  class="layui-btn" lay-submit="" lay-filter="btn-changesafe">立即修改</button>
						<button  style="color: rgb(240,222,112);background: rgb(57,61,73);font-size: 16px"  type="reset" class="layui-btn ">重置信息</button>
					</div>
				</div>
			</form>



		</div>
	</div>
</body>

<script type="text/javascript">
	layui.use('upload', function(){
		var form = layui.form,
		layer = layui.layer;

		var $ = layui.jquery
		,upload = layui.upload;

		form.render();

		//监听提交表单
		form.on('submit(btn-changepwd)', function(data){
			var oldpwd = data.field.oldpwd.trim();
			var newpwd = data.field.newpwd.trim();
			var confirm_newpwd = data.field.confirm_newpwd.trim();

			if ( oldpwd == newpwd ) {
                layer.msg('<span style="color: rgb(240,222,112);">新密码与原密码相同，请重新输入</span>');
				return false;
			}

			if ( newpwd != confirm_newpwd ) {
                layer.msg('<span style="color: rgb(240,222,112);">两次新密码不一致</span>');
				return false;
			}

			if (newpwd.length < 6 || confirm_newpwd.length < 6) {
                layer.msg('<span style="color: rgb(240,222,112);">新密码长度过短，建议长于>=6</span>');
				return false;
			}

			layer.confirm('确定修改密码？',{offset:'none'},function(index){
				$.ajax({
		            type: "post",
		            url: "{:U('Personal/ctrl_changePwd')}",
		            data: data.field,
		            dataType: "json",
		            success: function(rtJson){
		            	if (rtJson.code == 1) {
		            		$('#password-form')[0].reset();//重置表单
                            layer.msg('<span style="color: rgb(240,222,112);">'+rtJson.msg+'</span>');
		            	}else{
                            layer.msg('<span style="color: rgb(240,222,112);">'+rtJson.msg+'</span>');
		            	}
		            }
		        });
			});
	        return false;
		});


		//监听提交表单
		form.on('submit(btn-changesafe)', function(data){
			var oldsafe = data.field.oldsafe.trim();
			var newsafe = data.field.newsafe.trim();
			var confirm_newsafe = data.field.confirm_newsafe.trim();

			if ( oldsafe == newsafe ) {
                layer.msg('<span style="color: rgb(240,222,112);">新交易密码与原交易密码相同，请重新输入</span>');
				return false;
			}

			if ( newsafe != confirm_newsafe ) {
                layer.msg('<span style="color: rgb(240,222,112);">两次新交易密码不一致</span>');
				return false;
			}

			if (newsafe.length < 6 || confirm_newsafe.length < 6) {
                layer.msg('<span style="color: rgb(240,222,112);">新交易密码长度过短，建议长于>=6</span>');
				return false;
			}

			layer.confirm('确定修改交易密码？',{offset:'none'},function(index){
				$.ajax({
		            type: "post",
		            url: "{:U('Personal/ctrl_changeSafe')}",
		            data: data.field,
		            dataType: "json",
		            success: function(rtJson){
		            	if (rtJson.code == 1) {
		            		$('#safe-password-form')[0].reset();//重置表单
                            layer.msg('<span style="color: rgb(240,222,112);">'+rtJson.msg+'</span>');
		            	}else{
                            layer.msg('<span style="color: rgb(240,222,112);">'+rtJson.msg+'</span>');
		            	}
		            }
		        });
			});
	        return false;
		});

		
	});
</script>
<include file="Common/footer" />